package thread;

// 自定义线程任务类，实现Runnable接口
class MyRunnable implements Runnable {
    private String threadName;

    // 构造函数
    public MyRunnable(String name) {
        this.threadName = name;
        System.out.println("创建任务: " + name);
    }

    // 实现run()方法，定义线程执行的任务
    @Override
    public void run() {
        System.out.println("运行任务: " + threadName);
        try {
            for(int i = 1; i <= 5; i++) {
                System.out.println("任务 " + threadName + ": " + i);
                // 让线程睡眠一段时间
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            System.out.println("任务 " + threadName + " 被中断");
        }
        System.out.println("任务 " + threadName + " 完成");
    }
}
